Security News
Python Overtakes JavaScript as Top Programming Language on GitHub
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
@babel/plugin-transform-react-pure-annotations
Advanced tools
Mark top-level React method calls as pure for tree shaking
The @babel/plugin-transform-react-pure-annotations package is a Babel plugin designed to enhance optimization for React components by automatically annotating React components with `/*#__PURE__*/` comments. These comments signal to JavaScript bundlers and minifiers, such as Terser, that the component functions can be safely tree-shaken if they are not used. This can lead to smaller bundle sizes in production builds.
Automatic Pure Annotation for Functional Components
Automatically adds pure annotations to functional React components, indicating that they can be safely removed if unused.
Before:
const MyComponent = () => <div>Hello World</div>;
After:
const MyComponent = /*#__PURE__*/() => <div>Hello World</div>;
Automatic Pure Annotation for Class Components
Automatically adds pure annotations to the return value of render methods in class components, aiding in their potential tree-shaking.
Before:
class MyComponent extends React.Component {
render() {
return <div>Hello World</div>;
}
}
After:
class MyComponent extends React.Component {
render() {
return /*#__PURE__*/<div>Hello World</div>;
}
}
Transforms React.createElement calls to object literals. This can improve performance by reducing the overhead of these calls at runtime. However, it does not specifically focus on tree-shaking like @babel/plugin-transform-react-pure-annotations does.
Hoists element creation to the highest scope possible. This can improve performance in React applications by reducing the need to recreate the same elements on each render. While it optimizes performance, its approach is different from adding pure annotations for tree-shaking.
Mark top-level React method calls as pure for tree shaking
See our website @babel/plugin-transform-react-pure-annotations for more information.
Using npm:
npm install --save-dev @babel/plugin-transform-react-pure-annotations
or using yarn:
yarn add @babel/plugin-transform-react-pure-annotations --dev
v7.25.9 (2024-10-22)
babel-parser
, babel-template
, babel-types
syntacticPlaceholders
mode (@liuxingbaoyu)babel-helper-compilation-targets
, babel-preset-env
ClassAccessorProperty
to prevent the no-undef
rule (@victorenator)babel-parser
, babel-types
VISITOR_KEYS
etc. faster to access (@liuxingbaoyu)FAQs
Mark top-level React method calls as pure for tree shaking
The npm package @babel/plugin-transform-react-pure-annotations receives a total of 11,165,362 weekly downloads. As such, @babel/plugin-transform-react-pure-annotations popularity was classified as popular.
We found that @babel/plugin-transform-react-pure-annotations demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Python becomes GitHub's top language in 2024, driven by AI and data science projects, while AI-powered security tools are gaining adoption.
Security News
Dutch National Police and FBI dismantle Redline and Meta infostealer malware-as-a-service operations in Operation Magnus, seizing servers and source code.
Research
Security News
Socket is tracking a new trend where malicious actors are now exploiting the popularity of LLM research to spread malware through seemingly useful open source packages.